package com.intgrt.manager.ctrl;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONArray;
import com.intgrt.manager.service.SysMenuService;
import com.intgrt.manager.util.UserInfo;

@Controller
public class IndexCtrl {

	@Autowired
	private SysMenuService service;
	
	@RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.POST })
	public String home(HttpServletRequest request) {
		if (!SecurityUtils.getSubject().isAuthenticated() || UserInfo.getUser() == null) {
			return "login";
		}
		JSONArray menuList = service.getMenuArray(UserInfo.getId(),UserInfo.getRoleid());
		request.setAttribute("menulist", menuList);
		request.setAttribute("username", UserInfo.getAccname());
		return "index";
	}
	
}
